/**
 * 定义数采仪管理模块
 */
(function(window, angular, undefined){
	var dataCollectionInstrumetManagerModule = angular.module('water.apps.WasteWater.gyfsQyManager.gyfsInfo.dataCollectionInstrumetManager',['water.entity.dataCollectionInstrumet',
                                                                                                                               'water.apps.common.stationInfo.dataCollectionInstrumetManager',
                                                                                                                               'water.entity.monitorStation']);

	dataCollectionInstrumetManagerModule.controller('fsdataCollectionInstrumetManagerController',function($rootScope,$scope,$dataCollectionInstrumetService,$monitorStationService,$controller){
		
		/**
		 * 选择的污水处理厂id
		 */
		$scope.COMPANY_CODE;
		
		$controller("commonDataCollectionInstrumetManagerController",{$scope:$scope});
		$scope.dataPramChangedBroadCast();
		/**
		 * 监听站点列表点击事件
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			if($wdp.viewValue.wwtpDetailParm.COMPANY_CODE){
			$scope.COMPANY_CODE = $wdp.viewValue.wwtpDetailParm.COMPANY_CODE;
			$scope._getDataCollectionInstrumet();
			$scope._getStationSelectList();
			}
        },true);
		/**
		 * 获取数采仪列表
		 */
		$scope._getDataCollectionInstrumet = function(){
			if(!$scope.COMPANY_CODE){
				return;
			}
			$dataCollectionInstrumetService.getList({WWTP_ID:$scope.COMPANY_CODE}).then(function(d){
				$scope.dataCollectionInstrumetList = d.data
			});
		}
		/**
		 * 获取站点列表，编辑或者新增的时候需要选择
		 */
		$scope._getStationSelectList = function(){
			if(!$scope.COMPANY_CODE){
				return;
			}
			$monitorStationService.getList({WWTP_ID:$scope.COMPANY_CODE}).then(function(d){
				$scope.stationSelectList = [];
				for(var i=0;i<d.length;i++){
					$scope.stationSelectList.push({
						k:d[i].EXP_NO,
						v:d[i].NAME
					});
				}
				$scope.stationSelecter.setData($scope.stationSelectList);
				$scope.stationSelecterEdit.setData($scope.stationSelectList);
			});
		};
		
	});
}(window, angular));